﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Littlefish.Data;

namespace Littlefish.Model.Objects
{
    public class Address : BaseBusinessObject<Data.Address, Data.MainDataContext>
    {
        #region - Constructors -
        internal Address() : base() { }
        internal Address(MainDataContext context) : base(context) { }
        #endregion

        #region - Static Methods -
        public static Address GetAddress(int id)
        {
            return GetAddress(id, null, null);
        }
        public static Address GetAddress(int id, BusinessObjectOptions options)
        {
            return GetAddress(id, null, options);
        }
        public static Address GetAddress(int id, MainDataContext context)
        {
            return GetAddress(id, context, null);
        }
        public static Address GetAddress(int Id, MainDataContext context, BusinessObjectOptions options)
        {
            Address address = new Address(context);

            if (options != null)
                address.Options = options;

            address.Load(Id);
            return address;
        }

        public static IEnumerable<Address> GetAddresses()
        {
            MainDataContext context = new MainDataContext();
            List<Address> addresses = new List<Address>();
            var entities = from a in context.Addresses
                           orderby a.Id
                           select a;
            foreach (Data.Address address in entities)
            {
                Address a = new Address();
                a.Context = context;
                a.Entity = address;
                addresses.Add(a);
            }
            return addresses;
        }

        public static Address CreateAddress()
        {
            return CreateAddress(null, null);
        }
        public static Address CreateAddress(BusinessObjectOptions options)
        {
            return CreateAddress(null, options);
        }
        public static Address CreateAddress(MainDataContext context)
        {
            return CreateAddress(context, null);
        }
        public static Address CreateAddress(MainDataContext context, BusinessObjectOptions options)
        {
            Address a = new Address(context);

            if (options != null)
                a.Options = options;

            a.NewEntity();
            return a;
        }
        #endregion
    }
}
